package Homework.Top1.Test2;

import java.util.HashSet;
import java.util.*;
import java.util.ListIterator;

public class Company implements Comparable<Member>{
//    公司有公司名称，注册地址，电话，经营范围等属性
    private String name="合肥星宇娱乐有限公司";//公司名称
    private String address="宣城路111111号";//公司地址;
    private String phone="888-8899-1438";//公司电话
    private String business="资讯 影视 旅游";//经营范围

    Member mem=new Member();
    Set<Member> arry=new HashSet<>();
    public Company(){
        Member member1=new Member("李四",22,"男","财务",3200,"Q12321");
        Member member2=new Member("张三",22,"男","保安",2100,"Q12221");
        arry.add(member1);
        arry.add(member2);
    }
    public Company(String name, String address, String phone, String business) {
        this.name = name;
        this.address = address;
        this.phone = phone;
        this.business = business;
    }

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }

    public String getPhone() {
        return phone;
    }

    public String getBusiness() {
        return business;
    }

    public void print(){
        System.out.println(getName()+"\t地址："+getAddress()+"\t经营范围："+getBusiness()+"\t联系电话："+getPhone());
        System.out.println();
    }
    public void showList(){
        Iterator<Member> iterator=arry.iterator();
        System.out.println("姓名\t性别\t职务\t薪资\t工号");
        while (iterator.hasNext()){
            Member next=iterator.next();
            System.out.println(next.toString());
        }
    }

    public boolean addList(Member member){
        if (arry.size()==0){
            arry.add(member);
            return true;
        }else {
            for (Member member1 : arry) {
                if (member1.getWorkNum().equals(member.getWorkNum())){
                    return false;
                }
            }
        }
        arry.add(member);
        return true;
    }

    public boolean delete(String numWork){
        for (Member m : arry) {
            if (m.getWorkNum().equals(numWork)){
                arry.remove(m);
                return true;
            }else if (!m.getWorkNum().equals(numWork)){
                return false;
            }
        }
        return false;
    }

    public boolean raiseSalary(){
        for (Member member : arry) {
                if (compareTo(member)==1) {
                    member.setMoney(1000 + member.getMoney());
                    return true;
                }
        }
        return false;
    }

    public Member moneyMax(){
        Member member=new Member();
        Iterator<Member> iterator= arry.iterator();
        member=iterator.next();
        for (Member m:arry){
            if (m.getMoney()<m.getMoney()){
                member=m;
            }
        }
        return member;
    }
    @Override
    public int compareTo(Member o) {
       Iterator<Member> iterator= arry.iterator();
        while (iterator.hasNext()){
            if (o.getMeAge()<iterator.next().getMeAge()){
                return -1;
            }
        }
       return 1;
    }
}
